package com.i.userservice.util;

import cn.hutool.core.util.RandomUtil;

import java.security.SecureRandom;

/**
 * @author lewis
 * @type class
 * @description
 * @since 2024/10/24
 */
public class ValidateCodeUtil {
    private static SecureRandom secureRandom = RandomUtil.getSecureRandom();
    private static final String ALPHA_NUMERIC_STRING = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWSYZ";
    //生成随机数
    public static Integer generateRandomInt(int min, int max) {
        return secureRandom.nextInt((max - min) + 1) + min;
    }
    //生成随机字符串
    public static String generateRandomString(int length) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = secureRandom.nextInt(ALPHA_NUMERIC_STRING.length());
            builder.append(ALPHA_NUMERIC_STRING.charAt(index));
        }
        return builder.toString();
    }
}
